import { http } from "@/utils/request";
import {
  EmailCodeParams,
  emailLoginType,
  userLoginType,
  userRegisterType,
  loginReturnType,
} from "@/types/login";

/**
 *  发送邮箱验证码
 * @param email
 * @returns
 */
export const getEmailCodeAPI = (data: EmailCodeParams) => {
  return http<string>({
    method: "POST",
    url: "/api/v1/email/sendEmail",
    header: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data,
  });
};

export const userRegisterAPI = (data: userRegisterType) => {
  return http<string>({
    method: "POST",
    url: "/api/v1/users/register",
    data,
  });
};

/**
 * 传统登录-用户名+密码
 * @param data 请求参数
 */
export const postLoginAPI = (data: userLoginType) => {
  return http<loginReturnType>({
    method: "POST",
    url: "/api/v1/users/login",
    header: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data,
  });
};

export const postEmailLoginAPI = (data: emailLoginType) => {
  return http<loginReturnType>({
    method: "POST",
    url: "/api/v1/users/loginByEmail",
    header: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data,
  });
};
